package com.fy.market.trigger.listener;

import com.fy.market.strategy.model.entity.OrderMessageEntity;
import com.fy.market.types.common.constant.KeysConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author fwq
 * @description 抽奖订单消费者
 * @date 2025-10-10 20:49
 */
@Slf4j
@Component
public class LotteryOrderConsumer {

    // 消费者1
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = KeysConstant.MQKey.ORDER_CONSUME_QUEUE),
            exchange = @Exchange(name = KeysConstant.MQKey.ORDER_CONSUME_EXCHANGE),
            key = KeysConstant.MQKey.ORDER_CONSUME_ROUTING_KEY
    ), concurrency = "4")  // 这个消费者开4个线程
    public void consumer1(OrderMessageEntity orderMessageEntity) {
        log.info("🔥 消费者1收到消息：策略ID={}, 奖品ID={}, 用户ID={}", 
                orderMessageEntity.getStrategyId(), 
                orderMessageEntity.getAwardId(), 
                orderMessageEntity.getUserId());
    }

    // 消费者2
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = KeysConstant.MQKey.ORDER_CONSUME_QUEUE),
            exchange = @Exchange(name = KeysConstant.MQKey.ORDER_CONSUME_EXCHANGE),
            key = KeysConstant.MQKey.ORDER_CONSUME_ROUTING_KEY
    ), concurrency = "4")
    public void consumer2(OrderMessageEntity orderMessageEntity) {
        log.info("🔥 消费者2收到消息：策略ID={}, 奖品ID={}, 用户ID={}", 
                orderMessageEntity.getStrategyId(), 
                orderMessageEntity.getAwardId(), 
                orderMessageEntity.getUserId());
    }
}
